package com.puppy.service.impl;

import com.puppy.anno.LogOperation;
import com.puppy.mapper.EmpMapper;
import com.puppy.pojo.JobOption;
import com.puppy.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;

    @Override
    public JobOption getEmpJobCount() {
        //1.调用Mapper接口，获得统计数据
        List<Map<String, Object>> list = empMapper.countEmpJobData();

        //2.将统计数据封装
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("job")).toList();
        List<Object> countList = list.stream().map(dataMap -> dataMap.get("count")).toList();

        return new JobOption(jobList, countList);
    }

    @LogOperation // aop切面记录日志
    @Override
    public List<Map<String, Object>> getEmpGenderCount() {
        return empMapper.countEmpGenderData();
    }
}
